package com.antd.admin.server.controller;


import com.antd.admin.api.entity.SysDict;
import com.antd.admin.server.service.ISysDictService;
import com.antd.common.core.util.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author 子丶沫
 * @since 2021-06-09
 */
@RestController
@RequestMapping("/dict")
public class SysDictController {
    @Autowired
    private ISysDictService dictService;

    @GetMapping("/buildDictTree")
    @PreAuthorize("hasAnyAuthority('sys:dict:list')")
    public R<Object> getDictTree(String dictName){
        return R.ok(dictService.buildDictTree(dictName));
    }

    @PostMapping
    @PreAuthorize("hasAnyAuthority('sys:dict:save')")
    public R<Object> insertDict(@RequestBody SysDict dict){
        return R.ok(dictService.save(dict));
    }
    @PutMapping
    @PreAuthorize("hasAnyAuthority('sys:dict:update')")
    public R<Object> updateDict(@RequestBody SysDict dict){
        return R.ok(dictService.updateById(dict));
    }

    @DeleteMapping("/{id}")
    @PreAuthorize("hasAnyAuthority('sys:dict:delete')")
    public R<Object> deleteDict(@PathVariable("id") Long id){
        return R.ok(dictService.deleteDict(id));
    }
}
